package com.tool_stdy.utils.guava;

import java.util.Map;
import java.util.Set;

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import com.google.common.collect.Table.Cell;


/**
 * table有三列 分别为
 * rowKeySet   columnKeySet value
 * 
 * 获取全部数据为cellSet
 * @author yan_li
 *
 */
public class TableTest {

	public  static void tableTest() {
		Table<String, String, Integer> tables = HashBasedTable.create();

		tables.put("a", "java", 80);
		tables.put("b", "orcale", 75);
		tables.put("c", "html", 90);
		tables.put("a", "html", 80);
		
		//获取表的全部数据
		for(Cell<String, String, Integer> cel:tables.cellSet()){
			System.out.println(cel.getRowKey()+"--"+cel.getColumnKey()+"--"+cel.getValue());
		}
		System.out.println("***************");
		System.out.print("学生"+"\t");
		//获取所有的课程
		Set<String> course = tables.columnKeySet();
		for(String src:course){
			System.out.print(src+"\t");
		}
		System.out.println();
		//遍历所有学生
		for(String src:tables.rowKeySet()){
			Map<String, Integer> row = tables.row(src);
			System.out.print(src+'\t');
			for(String value:course){
				System.out.print(row.get(value)+"\t");
			}
			System.out.println();
		}
	}
	public static void main(String[] args) {
		tableTest();
	}
}
